//人员相关的配置
import axios from 'axios'
import {nanoid} from 'nanoid'
export default{
    namespaced: true,//使用命名空间下面名字才能在组件使用
    actions: {
        addPersonGuo(context, value) {
            if (value.name.indexOf('郭') === 0) {
                context.commit('ADD_PERSON', value)
            }else{
                alert('性不对')
            }

        },
        addPersonServe(context){
            axios.get('https://api.uixsj.cn/hitokoto/get?type=social').then(
				response => {
					context.commit('ADD_PERSON',{id:nanoid(),name:response.data})
				},
				error => {
					alert(error.message)
				}
			)
        }
    },
    mutations: {
        ADD_PERSON(state, value) {
            state.personList.unshift(value)
        }
    },
    state: {
        personList: [
            { id: '001', name: '123' },
            { id: '002', name: '123' },
            { id: '003', name: '123' },
        ]
    },
    getters: {
        firstPersonName(state) {
            return state.personList[0].name
        }
    }
}